package io.zhengsh.util;

import io.zhengsh.useragents.UserAgents;

import java.util.*;

public class HttpHeaderUtil {

    public static String USER_AGENT = "user-agent";

    public static Map<String, String> createHttpHeaders() {
        Map<String, String> headers = new HashMap<>();
        headers.put("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
        headers.put("accept-encoding", "gzip, deflate, br");
        headers.put("accept-language", "zh - CN, zh; q = 0.9, en; q = 0.8");
        headers.put("cache-control", "max-age=0");
        headers.put("dnt", "1");
        headers.put("if-none-match", " 29e3 b - FPMJepnFMXDyn5biD / M4I2Ywi6Q ");
        headers.put("referer", "https:www.baidu.com/3112" + RandomUtil.randomNum(10000));
        headers.put("sec-ch-ua", "\"Not A; Brand \";v=\" 99 \", \" Chromium \";v=\" 98 \", \" Google Chrome \";v=\" 98");
        headers.put("sec-ch-ua-mobile", "? 0 ");
        headers.put("sec-ch-ua-platform", getPlatform());
        headers.put("sec-fetch-dest", "document");
        headers.put("sec-fetch-mode", "navigate");
        headers.put("sec-fetch-site", "same-origin");
        headers.put("sec-fetch-user", "?1");
        headers.put("upgrade-insecure-requests", "1");
        return headers;
    }

    public static String getUserAgent() {
        return UserAgents.randomUserAgent();
    }

    public static String getPlatform() {
        List<String> platformList = Arrays.asList("macOS", "windows", "liunx");
        int i = RandomUtil.randomNum(100) % 3;
        return platformList.get(i);
    }
}
